package com.cloud.controller;

import com.cloud.dto.NewsDto;
import com.cloud.dto.UserDto;
import com.cloud.entity.News;
import com.cloud.entity.User;
import com.cloud.service.NewsService;
import com.cloud.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("news")
public class NewsController {
    @Autowired
    NewsService newsService;
    @Autowired
    UserService userService;

    //发送消息(假装已经get到了当前用户的id)
    @PostMapping("/SendNews")
    public Map SendNews(@RequestParam String info, @RequestParam Integer userId){
        Map map=new HashMap();
        UserDto userDto=userService.getUerById(userId);
        NewsDto newsDto= newsService.setNews(info, userDto);
        newsService.SendNews(newsDto);
        List<NewsDto> allNews= newsService.getAllNews(userDto.getTeamId());
        map.put("allNews",allNews);
        return map;
    }

    //进入聊天室(假装已经get到了当前用户的id)
    @GetMapping("/toChat")
    public Map toChat(Integer userId){
        Map map=new HashMap();
        UserDto userDto=userService.getUerById(userId);
        Integer teamId= userDto.getTeamId();
        List<NewsDto> newsDtoList=newsService.getAllNews(teamId);
        map.put("NewsList",newsDtoList);
        return map;
    }
}
